import {
	loginVerificationApi,
	getInfoApi
} from '@/api/login.js'
export default {
	state: {
		token: '', //token
		isStatus: false, //是否登录状态
		userInfo: {}, //用户信息,
		isBind: false,
	},
	mutations: {
		setBindStatus(state, isBind) {
			state.isBind = isBind
		},
		//存储token
		setToken(state, token) {
			state.token = token;
		},
		//存储用户信息
		setUserInfo(state, userInfo) {
			state.isStatus = true;
			state.userInfo = userInfo;
		},
		//退出登录
		loginOut(state) {
			state.isStatus = false;
			state.userInfo = {};
			state.token = '';
		}
	},
	actions: {
		async userLogin({
			commit,
			state
		}, data) {
			if (data) {
				var {
					token,
					user
				} = data;
			}

			if (state.token) {
				let res = await getInfoApi()
				commit('setUserInfo', res.data)
			} else {
				commit('setToken', token);
				commit('setUserInfo', user);
			}
		}
	}
}